package org.example.controller;

import org.example.api.user.FeignAuthorService;
import org.example.entity.dto.AuthorDTO;
import org.example.entity.vo.AuthorVO;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Aaron
 * @since 2020/12/23 13:15
 * <p>描述：</p>
 */
@RestController
@RequestMapping("/auth/author")
public class AuthorController extends BaseController {

    private final FeignAuthorService feignAuthorService;

    public AuthorController(FeignAuthorService feignAuthorService) {
        this.feignAuthorService = feignAuthorService;
    }


    @PostMapping("/save")
    public CommonResponse<Integer> saveAuthor(@RequestBody AuthorDTO authorDTO) {
        return this.feignAuthorService.saveAuthor(authorDTO);
    }

    @DeleteMapping("/{userId}")
    public CommonResponse<Integer> deleteAuthorById(@PathVariable Long userId) {
        return this.feignAuthorService.deleteAuthorById(userId);
    }

    @PutMapping("/update")
    public CommonResponse<Integer> updateAuthor(@RequestBody AuthorDTO authorDTO) {
        return this.feignAuthorService.updateAuthorById(authorDTO);
    }

    @PostMapping("/getAuthorById")
    public CommonResponse<AuthorDTO> getAuthorById(@RequestParam Long id) {
        return this.feignAuthorService.getAuthorById(id);
    }

    @PostMapping("/listAuthors")
    public CommonResponse<List<AuthorDTO>> listAuthors(@RequestBody AuthorVO authorVO) {
        AuthorDTO authorDTO = new AuthorDTO();
        BeanUtils.copyProperties(authorVO, authorDTO);
        return this.feignAuthorService.listAuthors(authorDTO);
    }

}
